package com.cy.pj.sys.web.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysRole;
import com.cy.pj.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role/")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;
    @GetMapping("checkRoles")
    public JsonResult doSelectCheckRoles(){
        return new JsonResult(sysRoleService.findCheckRoles());
    }
    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(sysRoleService.findById(id));
    }
    @PutMapping
    public JsonResult doUpdateRole(@RequestBody SysRole entity){
        sysRoleService.updateRole(entity);
        return new JsonResult("update ok");
    }
    @PostMapping
    public JsonResult doSaveRole(@RequestBody SysRole entity){
        sysRoleService.saveRole(entity);
        return new JsonResult("save ok");
    }
    @GetMapping
    public JsonResult doFindRoles(SysRole entity){
        Object o =  PageUtil.startPage().doSelectPageInfo(()->sysRoleService.findRoles(entity));
        return new JsonResult(o);
    }
}
